
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 
# P 140 Models
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 

# These include LogGDP Squared to facilitate replication.

# Note the alternative in the fifth position, about
# which our notes say it removes Islam as a control
# and "keeps the naming convention but is from a 
# different source"

p140base <- c("logGDPcap_2000 + logGDPcap2 + age15_64 + oil_gas_valuePOPred",
              "logGDPcap_2000 + logGDPcap2 + age15_64 + oil_gas_valuePOPred + 
              commie_2000 + me_nafr_2000 + islam_2000",
              #               "logGDPcap_2000 + logGDPcap2 + age15_64 + oil_gas_valuePOPred + 
              #                     commie_2000 + me_nafr_2000 + islam_2000 + oil_gas_valuePOPred_me",
              "logGDPcap_2000 + logGDPcap2 + age15_64 + oil_gas_valuePOPred + 
              commie_2000 + me_nafr_2000")

strwrap(p140base, width=10000, simplify=TRUE)
#names(p140base) <- c("A","B", "C", "D")
names(p140base) <- c("A","B","C")


p140early <- c("logGDPcap6372 + logGDPcap6372_sq + wdi_agedr_63 + oil_gas_pc_63",
               "logGDPcap6372 + logGDPcap6372_sq + wdi_agedr_63 + oil_gas_pc_63 + 
               commie_2000 + me_nafr_2000 + islam_2000",
               #                "logGDPcap6372 + logGDPcap6372_sq + wdi_agedr_63  +oil_gas_pc_63 + 
               #                       commie_2000 + me_nafr_2000 + islam_2000 + oil_gas_pc_63*me_nafr_2000",
               "logGDPcap6372 + logGDPcap6372_sq + wdi_agedr_63  + oil_gas_pc_63 + 
               commie_2000 + me_nafr_2000")
strwrap(p140early, width=10000, simplify=TRUE)
#names(p140early) <- c("A","B", "C", "D")
names(p140early) <- c("A","B","C")


# Now, alternative models that lack the
# squared term. Note on model WITHOUT Islam as a control

p140alt <- c("logGDPcap_2000 + age15_64 + oil_gas_valuePOPred",
             "logGDPcap_2000 + age15_64 + oil_gas_valuePOPred + 
             commie_2000 + me_nafr_2000 + islam_2000",
             #              "logGDPcap_2000 + age15_64 + oil_gas_valuePOPred + 
             #                     commie_2000 + me_nafr_2000 + islam_2000 + oil_gas_valuePOPred_me",
             "logGDPcap_2000 + age15_64 + oil_gas_valuePOPred + 
             commie_2000 + me_nafr_2000")
strwrap(p140alt, width=10000, simplify=TRUE)
#names(p140alt) <- c("A Alt","B Alt", "C Alt", "D Alt")
#names(p140alt) <- c("A Alt","B Alt", "C Alt")
names(p140alt) <- c("A","B","C")

p140earlyalt <- c("logGDPcap6372 +  wdi_agedr_63 + oil_gas_pc_63",
                  "logGDPcap6372 +  wdi_agedr_63 + oil_gas_pc_63 + 
                  commie_2000 + me_nafr_2000 + islam_2000",
                  #                   "logGDPcap6372+  wdi_agedr_63 + oil_gas_pc_63 + 
                  #                         commie_2000 + me_nafr_2000 + islam_2000 + oil_gas_pc_63*me_nafr_2000",
                  "logGDPcap6372 + wdi_agedr_63 + oil_gas_pc_63 + 
                  commie_2000 + me_nafr_2000") 
strwrap(p140earlyalt, width=10000, simplify=TRUE)
# names(p140earlyalt) <- c("A Alt","B Alt", "C Alt", "D Alt")
# names(p140earlyalt) <- c("A Alt","B Alt", "C Alt")
names(p140earlyalt) <- c("A","B","C")


p140.02 <- c("wdi_gdppccon_02_log + wdi_agedr_02 + oil_gas_pc_02",
             "wdi_gdppccon_02_log + wdi_agedr_02 + oil_gas_pc_02 + commie_2000 +
              me_nafr_2000 + islam_2000",
             "wdi_gdppccon_02_log + wdi_agedr_02 + oil_gas_pc_02 + commie_2000 +
               me_nafr_2000")
#names(p140.02) <- c("A Alt","B Alt", "C Alt")
names(p140.02) <- c("A","B","C")


p140.04 <- c("wdi_gdppccon_04_log + wdi_agedr_04 + oil_gas_pc_04",
               "wdi_gdppccon_04_log + wdi_agedr_04 + oil_gas_pc_04 + commie_2000 +
                me_nafr_2000 + islam_2000",
               "wdi_gdppccon_04_log + wdi_agedr_04 + oil_gas_pc_04 + commie_2000 +
               me_nafr_2000")
#names(p140.04) <- c("A Alt","B Alt", "C Alt")
names(p140.04) <- c("A","B","C")


p140.07 <- c("wdi_gdppccon_07_log + wdi_agedr_07 + oil_gas_pc_07",
               "wdi_gdppccon_07_log + wdi_agedr_07 + oil_gas_pc_07 + commie_2000 +
                me_nafr_2000 + islam_2000",
               "wdi_gdppccon_07_log + wdi_agedr_07 + oil_gas_pc_07 + commie_2000 +
               me_nafr_2000")
#names(p140.07) <- c("A Alt","B Alt", "C Alt")
names(p140.07) <- c("A","B","C")


p140.11 <- c("wdi_gdppccon_11_log + wdi_agedr_11 + oil_gas_pc_11",
               "wdi_gdppccon_11_log + wdi_agedr_11 + oil_gas_pc_11 + commie_2000 +
                me_nafr_2000 + islam_2000",
               "wdi_gdppccon_11_log + wdi_agedr_11 + oil_gas_pc_11 + commie_2000 +
               me_nafr_2000")
#names(p140.11) <- c("A Alt","B Alt", "C Alt")
names(p140.11) <- c("A","B","C")

#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 
# P 142 Models
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 

# This first set of models directly reproduce
# Ross's models from p. 142, with the exception
# of model #4a, which uses the standard
# World Bank definition of FLFP. Ross derogates
# this; note that it does inflate the impact
# of oil relative to Ross's definition.

# Because they are immaterial, we drop models
# using only per-cap GDP and the MENA dummy throughout. 
# We also ignore the model including 
# "logGDPcap_2000 me_nafr_2000 oil_gas_valuePOPred 
# islam_2000 avgflfp19932002"
# in favor of one using laborfemaleMOD_2000

p142base <- c("logGDPcap_2000 + me_nafr_2000 + oil_gas_valuePOPred",
              "logGDPcap_2000 + me_nafr_2000 + oil_gas_valuePOPred + islam_2000",
              "logGDPcap_2000 + me_nafr_2000 + oil_gas_valuePOPred + islam_2000 + laborfemaleMOD_2000",
              "logGDPcap_2000 + me_nafr_2000 + oil_gas_valuePOPred + islam_2000 + polity_2000")
names(p142base) <- c("D","E","F","G")


p142.02 <- c("wdi_gdppccon_02_log + me_nafr_2000 + oil_gas_pc_02",
              "wdi_gdppccon_02_log + me_nafr_2000 + oil_gas_pc_02 + islam_2000",
              "wdi_gdppccon_02_log + me_nafr_2000 + oil_gas_pc_02 + islam_2000 + wdi_lff_02",
              "wdi_gdppccon_02_log + me_nafr_2000 + oil_gas_pc_02 + islam_2000 + p_polity2_02")
names(p142.02) <- c("D","E","F","G")


p142.04 <- c("wdi_gdppccon_04_log + me_nafr_2000 + oil_gas_pc_04",
             "wdi_gdppccon_04_log + me_nafr_2000 + oil_gas_pc_04 + islam_2000",
             "wdi_gdppccon_04_log + me_nafr_2000 + oil_gas_pc_04 + islam_2000 + wdi_lff_04",
             "wdi_gdppccon_04_log + me_nafr_2000 + oil_gas_pc_04 + islam_2000 + p_polity2_04")
names(p142.04) <- c("D","E","F","G")


p142.07 <- c("wdi_gdppccon_07_log + me_nafr_2000 + oil_gas_pc_07",
             "wdi_gdppccon_07_log + me_nafr_2000 + oil_gas_pc_07 + islam_2000",
             "wdi_gdppccon_07_log + me_nafr_2000 + oil_gas_pc_07 + islam_2000 + wdi_lff_07",
             "wdi_gdppccon_07_log + me_nafr_2000 + oil_gas_pc_07 + islam_2000 + p_polity2_07")
names(p142.07) <- c("D","E","F","G")


p142.09 <- c("wdi_gdppccon_09_log + me_nafr_2000 + oil_gas_pc_09",
             "wdi_gdppccon_09_log + me_nafr_2000 + oil_gas_pc_09 + islam_2000",
             "wdi_gdppccon_09_log + me_nafr_2000 + oil_gas_pc_09 + islam_2000 + wdi_lff_09",
             "wdi_gdppccon_09_log + me_nafr_2000 + oil_gas_pc_09 + islam_2000 + p_polity2_09")
names(p142.09) <- c("D","E","F","G")


p142.11 <- c("wdi_gdppccon_11_log + me_nafr_2000 + oil_gas_pc_11",
             "wdi_gdppccon_11_log + me_nafr_2000 + oil_gas_pc_11 + islam_2000",
             "wdi_gdppccon_11_log + me_nafr_2000 + oil_gas_pc_11 + islam_2000 + wdi_lff_11",
             "wdi_gdppccon_11_log + me_nafr_2000 + oil_gas_pc_11 + islam_2000 + p_polity2_11")
names(p142.11) <- c("D","E","F","G")

# The second set of models updates the data
# from Ross's models above for the period 
# 2000-2009 for use with the smoking DV.

# Note that we do NOT update Islam. It's
# a slow-moving variable.

p142late <- c("wdi_gdppccon_09_log + me_nafr_2000 + oil_gas_pc_09",
              "wdi_gdppccon_09_log + me_nafr_2000 + oil_gas_pc_09 + islam_2000",
              "wdi_gdppccon_09_log + me_nafr_2000 + oil_gas_pc_09 + islam_2000 + wdi_lff_09",
              "wdi_gdppccon_09_log + me_nafr_2000 + oil_gas_pc_09 + islam_2000 + p_polity2_09")
names(p142late) <- c("D","E","F","G")

# The third set of models retrodates the data
# from Ross's models above for the period 
# 1963-1972. These are part of the 'harsh'
# replications which tend to assert that the
# causal factors are in the relationship between
# oil and selectorate theory, not in the short-run
# economic channel Ross propounds.

# Note here that we CAN use Ross's measure, so we do.

p142early <- c("logGDPcap6372 + me_nafr_2000 + oil_gas_pc_63",
               "logGDPcap6372 + me_nafr_2000 + oil_gas_pc_63 + islam6372",
               "logGDPcap6372 + me_nafr_2000 + oil_gas_pc_63 + islam6372 + laborfemaleMOD6372",
               "logGDPcap6372 + me_nafr_2000 + oil_gas_pc_63 + islam6372 + polity6372")
names(p142early) <- c("D","E","F","G")


# Log OIL GDP Per Capita

p140.02.log <- c("wdi_gdppccon_02_log + wdi_agedr_02 + oil_gas_pc_02_log",
                 "wdi_gdppccon_02_log + wdi_agedr_02 + oil_gas_pc_02_log + commie_2000 +
                 me_nafr_2000 + islam_2000",
                 "wdi_gdppccon_02_log + wdi_agedr_02 + oil_gas_pc_02_log + commie_2000 +
                 me_nafr_2000")
names(p140.02.log) <- c("A Alt","B Alt", "C Alt")


p140.04.log <- c("wdi_gdppccon_04_log + wdi_agedr_04 + oil_gas_pc_04_log",
                 "wdi_gdppccon_04_log + wdi_agedr_04 + oil_gas_pc_04_log + commie_2000 +
                 me_nafr_2000 + islam_2000",
                 "wdi_gdppccon_04_log + wdi_agedr_04 + oil_gas_pc_04_log + commie_2000 +
                 me_nafr_2000")
names(p140.04.log) <- c("A Alt","B Alt", "C Alt")


p140.07.log <- c("wdi_gdppccon_07_log + wdi_agedr_07 + oil_gas_pc_07_log",
                 "wdi_gdppccon_07_log + wdi_agedr_07 + oil_gas_pc_07_log + commie_2000 +
                 me_nafr_2000 + islam_2000",
                 "wdi_gdppccon_07_log + wdi_agedr_07 + oil_gas_pc_07_log + commie_2000 +
                 me_nafr_2000")
names(p140.07.log) <- c("A Alt","B Alt", "C Alt")


p140.11.log <- c("wdi_gdppccon_11_log + wdi_agedr_11 + oil_gas_pc_11_log",
                 "wdi_gdppccon_11_log + wdi_agedr_11 + oil_gas_pc_11_log + commie_2000 +
                 me_nafr_2000 + islam_2000",
                 "wdi_gdppccon_11_log + wdi_agedr_11 + oil_gas_pc_11_log + commie_2000 +
                 me_nafr_2000")
names(p140.11.log) <- c("A Alt","B Alt", "C Alt")


p142.02.log <- c("wdi_gdppccon_02_log + me_nafr_2000 + oil_gas_pc_02_log",
                 "wdi_gdppccon_02_log + me_nafr_2000 + oil_gas_pc_02_log + islam_2000",
                 "wdi_gdppccon_02_log + me_nafr_2000 + oil_gas_pc_02_log + islam_2000 + wdi_lff_02",
                 "wdi_gdppccon_02_log + me_nafr_2000 + oil_gas_pc_02_log + islam_2000 + p_polity2_02")
names(p142.02.log) <- c("D","E","F","G")


p142.04.log <- c("wdi_gdppccon_04_log + me_nafr_2000 + oil_gas_pc_04_log",
                 "wdi_gdppccon_04_log + me_nafr_2000 + oil_gas_pc_04_log + islam_2000",
                 "wdi_gdppccon_04_log + me_nafr_2000 + oil_gas_pc_04_log + islam_2000 + wdi_lff_04",
                 "wdi_gdppccon_04_log + me_nafr_2000 + oil_gas_pc_04_log + islam_2000 + p_polity2_04")
names(p142.04.log) <- c("D","E","F","G")


p142.07.log <- c("wdi_gdppccon_07_log + me_nafr_2000 + oil_gas_pc_07_log",
                 "wdi_gdppccon_07_log + me_nafr_2000 + oil_gas_pc_07_log + islam_2000",
                 "wdi_gdppccon_07_log + me_nafr_2000 + oil_gas_pc_07_log + islam_2000 + wdi_lff_07",
                 "wdi_gdppccon_07_log + me_nafr_2000 + oil_gas_pc_07_log + islam_2000 + p_polity2_07")
names(p142.07.log) <- c("D","E","F","G")


p142.11.log <- c("wdi_gdppccon_11_log + me_nafr_2000 + oil_gas_pc_11_log",
                 "wdi_gdppccon_11_log + me_nafr_2000 + oil_gas_pc_11_log + islam_2000",
                 "wdi_gdppccon_11_log + me_nafr_2000 + oil_gas_pc_11_log + islam_2000 + wdi_lff_11",
                 "wdi_gdppccon_11_log + me_nafr_2000 + oil_gas_pc_11_log + islam_2000 + p_polity2_11")
names(p142.11.log) <- c("D","E","F","G")



######
# Table Model Names
######
setwd("/Users/paulmusgrave/Dropbox/0001 Academic Projects/Ongoing/0127 Oil Islam Women/Work/Code/")
library(foreign)
tablenames <- read.csv("allmodels.csv", stringsAsFactors=FALSE)


prepper <- function(x,names=tablenames){
 # A function to prepare vectors of column labels
  # for the tabular presentation of results in the
  # appendix/supplementary information.
  foo <- strsplit(x,split=" ")
  foo <- unlist(foo)
  foo <- unique(foo)
  # Cleanup
  foo <- foo[which(foo!="+")]
  foo <- foo[which(foo!=" + ")]
  foo <- foo[which(foo!=" ")]
  foo <- foo[which(foo!="")]
  foo <- foo[which(foo!="\n")]
  foo <- foo[which(foo!="+\n")]
  
  foo2 <- rep(NA,length(foo))
  for(i in 1:length(foo)) 
    {
    foo2[i] <- names[which(names[,1]%in%foo[i]),2]
    }
  foo <- cbind(foo,foo2)
 # names(foo) <- names[which(names[,1]%in%foo),2]
colnames(foo) <- c("Variable","Label")
  return(foo)
}

p142.11.log.names <- prepper(p142.11.log)
p142.07.log.names <- prepper(p142.07.log)
p142.04.log.names <- prepper(p142.04.log)
p142.02.log.names <- prepper(p142.02.log)

p140.11.log.names <- prepper(p140.11.log)
p140.07.log.names <- prepper(p140.07.log)
p140.04.log.names <- prepper(p140.04.log)
p140.02.log.names <- prepper(p140.02.log)

p142early.names <- prepper(p142early)
p142late.names <- prepper(p142late)
p142base.names <- prepper(p142base)

p142.11.names <- prepper(p142.11)
p142.09.names <- prepper(p142.09)
p142.07.names <- prepper(p142.07)
p142.04.names <- prepper(p142.04)
p142.02.names <- prepper(p142.02)

p140.07.names <- prepper(p140.07)
p140.11.names <- prepper(p140.11)
p140.04.names <- prepper(p140.04)
p140.02.names <- prepper(p140.02)
p140earlyalt.names <- prepper(p140earlyalt)
p140alt.names <- prepper(p140alt)
p140early.names <- prepper(p140early)
p140base.names <- prepper(p140base)

